﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.Linq;
using System.Web.Security;

namespace Loja.customer
{
    public partial class Pedidos : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                using (LojaChocolateDCDataContext dc = new LojaChocolateDCDataContext())
                {
                    var pedidos = dc.GetTable<Pedido>();
                    short cliID = ((Cliente)Session["Cliente"]).CliID;
                    txtDatIni.Text = String.Format("{0:d}", DateTime.Now.AddDays(-30));
                    txtDatFim.Text = String.Format("{0:d}", DateTime.Now);
                    rptPedidos.DataSource = pedidos.Where(p => p.CliID == cliID).OrderByDescending(p => p.PedDat).Take(6);
                    rptPedidos.DataBind();
                }
            }

            string script = @"$(document).ready(function () {
                                $( '#radio' ).buttonset();
                                $('.botao').button();
                                data();
                            });";
            ScriptManager.RegisterClientScriptBlock(Page, Page.GetType(), "tela", script, true);
        }

        protected void btnPesquisar_Click(object sender, EventArgs e)
        {

        }

        protected void pesquisar()
        {

            using (LojaChocolateDCDataContext dc = new LojaChocolateDCDataContext())
            {
                short cliID = ((Cliente)Session["cliente"]).CliID;
                DateTime dataInicial, dataFinal;
                dataInicial = DateTime.Parse(txtDatIni.Text);
                dataFinal = DateTime.Parse(txtDatFim.Text);
                Table<Pedido> tblPedido = dc.GetTable<Pedido>();
                rptPedidos.DataSource = tblPedido.Where(p => p.CliID == cliID && (p.PedDat >= dataInicial && p.PedDat <= dataFinal)).
                                        OrderByDescending(p => p.PedDat);
                rptPedidos.DataBind();
            }
        }


    }
}